<template>
  <div class="setting-wrapper">
    <div class="setting-left">
      <el-menu
        :default-active="activeName"
        collapse
        class="el-menu-vertical-demo"
        @select="changeSetting"
      >
        <el-menu-item index="base">
          <i class="el-icon-s-tools"></i>
          <span slot="title">基础设置</span>
        </el-menu-item>
        <el-menu-item index="warning">
          <i class="el-icon-warning"></i>
          <span slot="title">告警设置</span>
        </el-menu-item>
      </el-menu>
    </div>
    <div class="setting-right">
      <el-card>
        <div slot="header" class="clearfix">
          <span style="font-size: 16px">{{ menuname }}</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="save">保存</el-button>
        </div>
        <keep-alive>
          <component ref="setting" :is="comname" :id="id"></component>
        </keep-alive>
      </el-card>
    </div>
  </div>
</template>
<script>
import TaskSettingBase from "./task-setting-base";
import TaskSettingWarning from "./task-setting-warning";
export default {
  name: "TaskSetting",
  components: {
    TaskSettingBase,
    TaskSettingWarning
  },
  props: {
    id: String
  },
  data() {
    return {
      activeName: "base"
    };
  },
  computed: {
    comname() {
      return `task-setting-${this.activeName}`;
    },
    menuname() {
      let { activeName } = this;
      return activeName === "base" ? "基础设置" : "告警设置";
    }
  },
  methods: {
    changeSetting(index) {
      this.activeName = index;
    },
    // 设置保存
    save() {
      this.$refs.setting.save();
    }
  }
};
</script>
<style lang="scss">
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.setting-wrapper {
  display: flex;
  .setting-right {
    flex: 1;
    & > .el-card {
      border: none;
      box-shadow: none;
    }
    .el-card__header {
      padding: 16px 20px;
    }
  }
  .el-menu {
    height: 100%;
  }
}
</style>
